<template>
  <div class="bottom-right-table-3">
    <dv-border-box-6>
      <div class="table-name">
        <img src="./img/icon3.png" />常见故障排行
      </div>

      <dv-scroll-board :config="config" />
    </dv-border-box-6>
  </div>
</template>

<script>
export default {
  props: {
    chartData: {
      type: Object,
      required: true
    }
  },
  name: 'BottomRightTable3',
  data () {
    return {
      config: {
        data: [],
        index: true,
        columnWidth: [30, 100],
        align: ['center'],
        oddRowBGC: 'rgba(9, 37, 50, 0.4)',
        evenRowBGC: 'rgba(10, 32, 50, 0.3)'
      }
    }
  },
  watch: {
    chartData: {
      handler(newData) {
        if (newData != null && newData.fault !== undefined) {
          const faultCommons = newData.fault.faultCommon
          this.config = {
            data: this.getValue(faultCommons),
            index: true,
            columnWidth: [30],
            align: ['left'],
            oddRowBGC: 'rgba(9, 37, 50, 0.4)',
            evenRowBGC: 'rgba(10, 32, 50, 0.3)'
          }
        }
      },
      immediate: true,
      deep: true
    }
  },
  methods: {
    getValue(faultPlaces) {
      const arr = [];
      for (const faultPlace of faultPlaces) {
        arr.push([faultPlace.name, '月累计：' + faultPlace.count + '起'])
      }
      return arr
    }
  }
}
</script>

<style lang="scss">
.bottom-right-table-3 {
  width: calc(25% + 10px);
  height: 100%;
  margin: 0 -5px;

  .border-box-content {
    padding: 20px;
    box-sizing: border-box;
  }

  .table-name {
    height: 45px;
    display: flex;
    justify-content: center;
    align-items: center;
    margin-bottom: 15px;

    img {
      width: 40px;
      height: 40px;
      margin-right: 5px;
    }
  }

  .dv-scroll-board {
    height: calc(100% - 60px);
  }
}
</style>
